<?php

namespace common\models\searchs;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\DhProject;

/**
 * SearchProject represents the model behind the search form about `\common\models\DhProject`.
 */
class SearchProject extends DhProject
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'c_id', 'flag', 'creat_time'], 'integer'],
            [['content', 'title','unit'], 'safe'],
            [['price'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = DhProject::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        $query->andFilterWhere([

            'flag' => 1,
        ]);
        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'c_id' => $this->c_id,
            'price' => $this->price,
            'flag' => $this->flag,
            'creat_time' => $this->creat_time,

        ]);

        $query->andFilterWhere(['like', 'content', $this->content])
            ->andFilterWhere(['like', 'title', $this->title]);

        return $dataProvider;
    }
}
